#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char str[maxn];
LL suf[maxn];
stack<char>s;
int main(void)
{
  	cin.tie(0);std::ios::sync_with_stdio(false);
    cin>>(str+1);LL n=strlen(str+1);
    memset(suf,0x3f,sizeof(suf));
    for(LL i=n;i>=1;i--){
        suf[i]=min(suf[i+1],(LL)(str[i]-'a'+1));
    }
    vector<char>v;
    for(LL i=1;i<=n;i++){
        if(s.empty()){
            s.push(str[i]);
        }
        else{
            while(!s.empty()){
                if((s.top()-'a'+1)<=suf[i]){
                    v.push_back(s.top());
                    s.pop();
                }
                else break;
            }
            s.push(str[i]);
        }
    }
    while(!s.empty()){
        v.push_back(s.top());s.pop();
    }
    for(auto i:v){
        cout<<i;
    }
    cout<<"\n";
return 0;
}
